package com.Maykk.charStream;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

/**
 * @ClassName: Demo01
 * @Description: TODO 字符编码测试
 * @Author: MaykkStar@163.com
 */
public class Demo01 {
    public static void main(String[] args) throws UnsupportedEncodingException {
        String s = "abcdef天津";
        byte[] bytes = s.getBytes("UTF-8");
        byte[] bytesGBK = s.getBytes("GBK");

        // UTF-8 汉字占用3个字节
        System.out.println(Arrays.toString(bytes));
        // GBK 汉字占用两个字节
        System.out.println(Arrays.toString(bytesGBK));
        System.out.println(new String(bytes, "UTF-8"));
        System.out.println(new String(bytesGBK, "GBK"));
    }
}